package com.ray.monitor.table.vo;

import java.io.Serializable;
import java.util.Set;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import com.xiaoleilu.hutool.util.HashUtil;
import com.xiaoleilu.hutool.util.StrUtil;


public class HostBO implements Serializable{
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String host;
    private String port;

    public HostBO(){}
    public HostBO(String host, String port) {
        this.host = host;
        this.port = port;
    }

    public String getHostString(){
        if(port == null){
            return host;
        }
        return host+":"+port;
    }


    //======host 页面展示所用====
    Set<String> providers;
    Set<String> consumers;

    //服务名--即dba定义的该ip地址的名称
    String hostName;
    //对应的另外一个ip
    String anotherIp;
    @SuppressWarnings("unused")
    private String providerName;
    @SuppressWarnings("unused")
    private String consumerName;
    @SuppressWarnings("unused")
	private Boolean status = false;


	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}
	public String getPort() {
		return port;
	}
	public void setPort(String port) {
		this.port = port;
	}
	public Set<String> getProviders() {
		return providers;
	}
	public void setProviders(Set<String> providers) {
		this.providers = providers;
	}
	public Set<String> getConsumers() {
		return consumers;
	}
	public void setConsumers(Set<String> consumers) {
		this.consumers = consumers;
	}
	public String getHostName() {
		return hostName;
	}
	public void setHostName(String hostName) {
		this.hostName = hostName;
	}
	public String getAnotherIp() {
		return anotherIp;
	}
	public void setAnotherIp(String anotherIp) {
		this.anotherIp = anotherIp;
	}
	
	@Override
    public boolean equals(Object obj) {
        if(!(obj instanceof HostBO)) {
            return false;
        }
        HostBO b = (HostBO)obj;
        if(StrUtil.equals(this.getHostString(), b.getHostString())) {
            return true;
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return HashUtil.apHash(getHostString());
    }
	public String getProviderName() {
		if(providers == null) return null;
		return StringUtils.join(providers.toArray(), ",");
	}
	public void setProviderName(String providerName) {
		this.providerName = providerName;
	}
	public String getConsumerName() {
		if(consumers == null) return null;
		return StringUtils.join(consumers.toArray(), ",");
	}
	public void setConsumerName(String consumerName) {
		this.consumerName = consumerName;
	}
	public Boolean getStatus() {
		return providers != null && !providers.isEmpty() ;
	}
    
}
